﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;
using System.IO;
namespace NHA_HANG_BUFFET
{
    public partial class frmQuanLyBep : DevComponents.DotNetBar.Office2007Form
    {
        public frmQuanLyBep()
        {
            InitializeComponent();
        }
        //string thu=null;
        
        private void frmQuanLyBep_Load(object sender, EventArgs e)
        {
            BUS.busCuong bc = new busCuong();
           
        }
        private void lbThu2_Click_1(object sender, EventArgs e)
        {
            lbThu2.BackColor = Color.Red;
            lbthu3.BackColor = Color.DodgerBlue;
            lbthu4.BackColor = Color.DodgerBlue;
            lbthu5.BackColor = Color.DodgerBlue;
            lbthu6.BackColor = Color.DodgerBlue;
            lbthu7.BackColor = Color.DodgerBlue;
            lbchunhat.BackColor = Color.DodgerBlue;
            //MessageBox.Show(lbThu2.Text);
            //thu = "Thu" + lbThu2.Text;
            //BUS.busCuong bc = new busCuong();
            //dgv_thucdondutru.DataSource = bc.dao_thu2("thu 2", Convert.ToDateTime(ngaybatdau.Value), Convert.ToDateTime(ngayketthuc.Value));

        }

        private void lbthu3_Click(object sender, EventArgs e)
        {
            lbthu3.BackColor = Color.Red;
            lbThu2.BackColor = Color.DodgerBlue;
            lbthu4.BackColor = Color.DodgerBlue;
            lbthu5.BackColor = Color.DodgerBlue;
            lbthu6.BackColor = Color.DodgerBlue;
            lbthu7.BackColor = Color.DodgerBlue;
            lbchunhat.BackColor = Color.DodgerBlue;
            //thu = "Thu" + lbthu3.Text;
        //    BUS.busCuong bc = new busCuong();
        //    dgv_thucdondutru.DataSource = bc.dao_thu3("thu 3", Convert.ToDateTime(ngaybatdau.Value), Convert.ToDateTime(ngayketthuc.Value));

        }

        private void lbthu4_Click(object sender, EventArgs e)
        {
            lbthu4.BackColor = Color.Red;
            lbThu2.BackColor = Color.DodgerBlue;
            lbthu3.BackColor = Color.DodgerBlue;
            lbthu5.BackColor = Color.DodgerBlue;
            lbthu6.BackColor = Color.DodgerBlue;
            lbthu7.BackColor = Color.DodgerBlue;
            lbchunhat.BackColor = Color.DodgerBlue;
            //thu = "Thu" + lbthu4;
        }

        private void lbthu5_Click(object sender, EventArgs e)
        {
            lbthu5.BackColor = Color.Red;
            //BUS.busCuong bc = new busCuong();
            //dgv_thucdondutru.DataSource = bc.dao_thu5("thu 5", Convert.ToDateTime(ngaybatdau.Value), Convert.ToDateTime(ngayketthuc.Value));
            lbThu2.BackColor = Color.DodgerBlue;
            lbthu4.BackColor = Color.DodgerBlue;
            lbthu3.BackColor = Color.DodgerBlue;
            lbthu6.BackColor = Color.DodgerBlue;
            lbthu7.BackColor = Color.DodgerBlue;
            lbchunhat.BackColor = Color.DodgerBlue;
           // thu = "Thu" + lbthu5;
        }

        private void lbthu6_Click(object sender, EventArgs e)
        {
            lbthu6.BackColor = Color.Red;
            lbThu2.BackColor = Color.DodgerBlue;
            lbthu4.BackColor = Color.DodgerBlue;
            lbthu5.BackColor = Color.DodgerBlue;
            lbthu3.BackColor = Color.DodgerBlue;
            lbthu7.BackColor = Color.DodgerBlue;
            lbchunhat.BackColor = Color.DodgerBlue;
            //thu = "Thu" + lbthu6;
         }

        private void lbthu7_Click(object sender, EventArgs e)
        {
            lbthu7.BackColor = Color.Red;
            lbThu2.BackColor = Color.DodgerBlue;
            lbthu4.BackColor = Color.DodgerBlue;
            lbthu5.BackColor = Color.DodgerBlue;
            lbthu6.BackColor = Color.DodgerBlue;
            lbthu3.BackColor = Color.DodgerBlue;
            lbchunhat.BackColor = Color.DodgerBlue;
            //thu = "Thu" + lbthu7;
        }

        private void lbchunhat_Click(object sender, EventArgs e)
        {
            lbchunhat.BackColor = Color.Red;
            lbThu2.BackColor = Color.DodgerBlue;
            lbthu4.BackColor = Color.DodgerBlue;
            lbthu5.BackColor = Color.DodgerBlue;
            lbthu6.BackColor = Color.DodgerBlue;
            lbthu7.BackColor = Color.DodgerBlue;
            lbthu3.BackColor = Color.DodgerBlue;
            //thu = "Thu" + lbchunhat;
        }

    //------hiển thị đường dẫn theo ngày ap dung ----------------------------------------------------
        //private void hienthithudondabantheongaybatdau(DateTime ngaybd)
        //{
        //    BUS.busCuong bc = new busCuong();
        //    // dgv_baocao.DataSource = bc.dao_tatca(ngaybd ,ngaykt);
        //    DataTable dt = new DataTable();
        //    int stt = 0;
        //    dt = bc.LayDSTheoNgayBatDau(ngaybd);
           
        //    for (int i = 0; i < dt.Rows.Count; i++)
        //    {
                
        //        stt++;
        //        dgv_baocao.Rows.Add(stt.ToString(), dt.Rows[i]["MaDV"], dt.Rows[i]["TenDV"], dt.Rows[i]["sl"]);
        //    }

        //}
        private void hienthithudondaban(DateTime ngaybd, DateTime ngaykt)
        {
            BUS.busCuong bc = new busCuong();
            DataTable dt = new DataTable();
            int stt = 0;
            dt = bc.dao_tatca(ngaybd, ngaykt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                stt++;
                dgv_baocao.Rows.Add(stt.ToString(), dt.Rows[i]["MaDV"], dt.Rows[i]["TenDV"], dt.Rows[i]["sl"]);
            }

        }
        //chú ý-----------------------------------------------------------------------------------------------
        //private void hienthidanhsachnguyelieucuathucdon(string tennl)
        //{
        //    BUS.busCuong bc = new busCuong();
        //    DataTable dt = new DataTable();
        //    int stt = 0;
        //    dt = bc.dao_danhsachnguyenlieu(tennl);
        //    for (int i = 0; i < dt.Rows.Count; i++)
        //    {
        //        stt++;
        //        dgv_nguyenlieuthucdon.Rows.Add(stt.ToString(), dt.Rows[i]["MaDV"], dt.Rows[i]["TenNL"], dt.Rows.Add[i]["LoaiNL"], dt.Rows.Add[i]["DonVi"], dt.Rows.Add[i]["SoLuongTon"]);
        //    }
        //}
        //private void dtime_NgayBatDau_TextChanged(object sender, EventArgs e)
        //{
        //    dgv_baocao.Rows.Clear();
        //    hienthithudondabantheongaybatdau(dtime_NgayBatDau.Value);
        //}
        private void dtime_NgayKT_TextChanged(object sender, EventArgs e)
        {
            dgv_baocao.Rows.Clear();
            hienthithudondaban(dtime_NgayBatDau.Value, dtime_NgayKT.Value);
            ////dgv_baocao.Rows.Clear();
            //hienthiduongdantheongaykt(dtime_NgayBatDau.Value, dtime_NgayKT.Value);
            ////bc.dao_tatca(dtime_NgayBatDau.Value);

        }

        private void dgv_baocao_CellClick(object sender, DataGridViewCellEventArgs e)
        {
           
            //if (e.ColumnIndex==4)
            //{
               // for (int i = 0; i < dgv_baocao.Rows.Count; i++)
               // {
                    if (e.ColumnIndex == 4)//Add
                    {
                        //Kiem tra mamonan
                        dgv_thucdondutru.Rows.Add(dgv_baocao.Rows[e.RowIndex].Cells["STT"].Value.ToString(),dgv_baocao.Rows[e.RowIndex].Cells["MaMon"].Value.ToString(),dgv_baocao.Rows[e.RowIndex].Cells["tenmonan"].Value.ToString());
                    }
                //}
            //}
        }



        public void LayDSNVL(int MaDV)
        {
            BUS.busCuong bc = new busCuong();
            dgv_danhsachnguyenlieu.DataSource = bc.bLayDSNVL(MaDV);
        }

        private void dgv_thucdondutru_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int vitri = e.RowIndex;
            string tam = dgv_danhsachnguyenlieu.Rows[vitri].Cells[0].Value.ToString();
            int tam1 = int.Parse(tam.ToString());
            //dgvChiTietPhieuYC.Rows.Clear();
            LayDSNVL(tam1);
        }

        private void bttLuu_Click_1(object sender, EventArgs e)
        {
            //Lay ma tuan
            string tentuan = "tuần ";
            BUS.busCuong bc = new busCuong();
            DataTable dt = new DataTable();
            DataTable dt2 = new DataTable();
            dt = bc.LayDSThucDonDuTru();
            int stt = dt.Rows.Count + 1;
            tentuan = tentuan + stt;
            ThucDonDuTru tddt = new ThucDonDuTru();

            //List<CTThucDon> list_tddt = new List<CTThucDon>();
            //Dua du lieu vao
            tddt.TenTuan = tentuan;
            tddt.NgayBatDau = ngaybatdau.Value;
            tddt.NgayKetThuc = ngayketthuc.Value;
            //if (thu == null)
            //{
            //    MessageBox.Show("Chua chon thu");
            //}
            //else
            // {
            if (bc.ThemThucDonDuTru(tddt))
            {
                dt2 = bc.LayDSThucDonDuTru();
                int matuan = Int16.Parse(dt2.Rows[0]["MaTuan"].ToString());
                for (int i = 0; i < dgv_thucdondutru.Rows.Count - 1; i++)
                {
                    CTThucDon cttd = new CTThucDon();

                    DateTime ngayhientai = DateTime.Now;
                    cttd.MaDV = Int16.Parse(dgv_thucdondutru.Rows[i].Cells["MaDV"].Value.ToString());
                    cttd.MaTuan = matuan;
                    cttd.NgayApDung = ngayhientai;
                    if (dgv_thucdondutru.Rows[i].Cells["ThuMay"].Value == null)
                    {
                        MessageBox.Show("chưa nhập thứ:");
                    }
                    else
                    {
                        cttd.Thu = dgv_thucdondutru.Rows[i].Cells["ThuMay"].Value.ToString();
                    }



                    if (dgv_thucdondutru.Rows[i].Cells["colSoPhan"].Value == null)
                    {
                        MessageBox.Show("Chua nhap phan ban");

                    }
                    else
                    {
                        cttd.SoPhanBan = Int16.Parse(dgv_thucdondutru.Rows[i].Cells["colSoPhan"].Value.ToString());
                    }
                    // cttd.Thu = thu;
                    bc.ThemCTThucDon(cttd);
                }
                MessageBox.Show("Them thanh cong");
            }
            else
            {
                MessageBox.Show("Them that bai");
            }

        }

        private void dgv_thucdondutru_CellClick_1(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 5)
                {
                    dgv_thucdondutru.Rows.RemoveAt(e.RowIndex);
                
                }
            }
            catch
            {
                return;
            }
        }

        

        
        
    }
}
